package com.bot.edu.employmentsystem.employmen.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.oConvertUtils;
import com.bot.edu.employmentsystem.employmen.entity.EmploymenInformation;
import com.bot.edu.employmentsystem.employmen.service.IEmploymenInformationService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: 就业信息表
 * @Author: jeecg-boot
 * @Date:   2022-04-07
 * @Version: V1.0
 */
@Api(tags="就业信息表")
@RestController
@RequestMapping("/employmen/employmenInformation")
@Slf4j
public class EmploymenInformationController extends JeecgController<EmploymenInformation, IEmploymenInformationService> {
	@Autowired
	private IEmploymenInformationService employmenInformationService;
	
	/**
	 * 分页列表查询
	 *
	 * @param employmenInformation
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "就业信息表-分页列表查询")
	@ApiOperation(value="就业信息表-分页列表查询", notes="就业信息表-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<EmploymenInformation>> queryPageList(EmploymenInformation employmenInformation,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<EmploymenInformation> queryWrapper = QueryGenerator.initQueryWrapper(employmenInformation, req.getParameterMap());
		Page<EmploymenInformation> page = new Page<EmploymenInformation>(pageNo, pageSize);
		IPage<EmploymenInformation> pageList = employmenInformationService.page(page, queryWrapper);
		return Result.OK(pageList);
	}


	 /**
	  * C端  根据学生查询就业信息
	  *
	  * @param stuId
	  * @param req
	  * @return employmenInfo
	  */
	 //@AutoLog(value = "就业信息表-分页列表查询")
	 @ApiOperation(value="就业信息表-C端  根据学生查询就业信息", notes="就业信息表-C端  根据学生查询就业信息")
	 @PostMapping(value = "/showEmployInfoByStuId")
	 public Result<?> showEmployInfoByStuId(@RequestParam("stuId")String stuId,
															  HttpServletRequest req) {
		 EmploymenInformation employmenInformation = new EmploymenInformation();
		 employmenInformation.setStuId(stuId);
		 QueryWrapper<EmploymenInformation> queryWrapper = QueryGenerator.initQueryWrapper(employmenInformation, req.getParameterMap());
		 queryWrapper.lambda().eq(EmploymenInformation::getStuId,stuId);
		 EmploymenInformation employmenInfo = employmenInformationService.getOne(queryWrapper);
		 return Result.OK(employmenInfo);
	 }

	
	/**
	 *   添加
	 *
	 * @param employmenInformation
	 * @return
	 */
	@AutoLog(value = "就业信息表-添加")
	@ApiOperation(value="就业信息表-添加", notes="就业信息表-添加")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody EmploymenInformation employmenInformation) {
		employmenInformationService.save(employmenInformation);
		return Result.OK("添加成功！");
	}





	
	/**
	 *  编辑
	 *
	 * @param employmenInformation
	 * @return
	 */
	@AutoLog(value = "就业信息表-编辑")
	@ApiOperation(value="就业信息表-编辑", notes="就业信息表-编辑")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody EmploymenInformation employmenInformation) {
		employmenInformationService.updateById(employmenInformation);
		return Result.OK("编辑成功!");
	}

	 /**
	  *   C端  学生  更新就业信息
	  *
	  * @param employmenInformation
	  * @return
	  */
	 @AutoLog(value = "就业信息表-更新")
	 @ApiOperation(value="就业信息表-更新", notes="就业信息表-更新")
	 @PostMapping(value = "/updateEmplomenInfoByStuId")
	 public Result<String> updateEmplomenInfoByStuId(@RequestBody EmploymenInformation employmenInformation) {

		 Date nowDate = new Date();

		 employmenInformation.setUpdateTime(nowDate);
	 	 employmenInformationService.updateById(employmenInformation);
		 return Result.OK("更新成功！");
	 }

	 /**
	  *  C端  保存失败原因
	  *
	  * @param failureCase
	  * @param stuId
	  * @return
	  */

	 @RequestMapping(value = "/saveFailureCause", method = {RequestMethod.PUT,RequestMethod.POST})
	 public Result<String> edit(@RequestParam("failureCause")String failureCase,
								@RequestParam("stuId")String stuId) {
		 UpdateWrapper<EmploymenInformation> updateWrapper = new UpdateWrapper<>();
		 updateWrapper.lambda()
				 .eq(EmploymenInformation::getStuId,stuId)
				 .set(EmploymenInformation::getFailureCause,failureCase);
		 employmenInformationService.update(updateWrapper);
		 return Result.OK("编辑成功!");
	 }
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "就业信息表-通过id删除")
	@ApiOperation(value="就业信息表-通过id删除", notes="就业信息表-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		employmenInformationService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "就业信息表-批量删除")
	@ApiOperation(value="就业信息表-批量删除", notes="就业信息表-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.employmenInformationService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "就业信息表-通过id查询")
	@ApiOperation(value="就业信息表-通过id查询", notes="就业信息表-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<EmploymenInformation> queryById(@RequestParam(name="id",required=true) String id) {
		EmploymenInformation employmenInformation = employmenInformationService.getById(id);
		if(employmenInformation==null) {
			return Result.error("未找到对应数据",null);
		}
		return Result.OK(employmenInformation);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param employmenInformation
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, EmploymenInformation employmenInformation) {
        return super.exportXls(request, employmenInformation, EmploymenInformation.class, "就业信息表");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, EmploymenInformation.class);
    }

}
